package com.snake.springboot.custom.controller.base;

import com.snake.springboot.custom.api.model.base.CustMainAccountModel;
import com.snake.springboot.custom.api.request.base.MainAccPwdReq;
import com.snake.springboot.custom.api.service.base.CustMainAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.snake.common.result.ResponseResult;
import org.snake.common.result.ResponseResultFactory;
import org.snake.common.utils.IllegalStrUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>商户主账号
 * 类{@code CustomMainAccount} </br>
 * 创建时间2025/2/8 11:55
 * @author yangxt
 * @see
 */
@Api(tags = "商户主账号")
@RestController
@RequestMapping("/cust/main-acc")
public class CustMainAccController {

    private CustMainAccountService accountService;
    @Autowired
    public CustMainAccController(CustMainAccountService accountService) {
        this.accountService = accountService;
    }

    @ApiOperation("修改商户主账号")
    @PostMapping("/modify")
    public ResponseResult<CustMainAccountModel> modifyCustomMainAccount(
            @ApiParam(name = "接口模型入参", value = "传入json格式", required = true)
            @RequestBody CustMainAccountModel model) {
        accountService.modifyCustomMainAccount(model);
        return ResponseResultFactory.ucc("修改成功！");
    }

    @ApiOperation("修改商户主账号密码")
    @PostMapping("/me/update-password")
    public ResponseResult<Object> updatePwdByMe(
            @ApiParam(name = "记录ID", value = "传入String类型", required = true)
            @RequestBody MainAccPwdReq pwdReq) {
        IllegalStrUtils.checkPwd(pwdReq.getPassword());
        accountService.updatePwdByMe(pwdReq);
        return ResponseResultFactory.ucc("修改密码成功！");
    }

    @ApiOperation("管理员修改商户主账号密码")
    @PostMapping("/admin/update-password")
    public ResponseResult<Object> updatePwdByAdmin(
            @ApiParam(name = "记录ID", value = "传入String类型", required = true)
            @RequestBody MainAccPwdReq pwdReq) {
        IllegalStrUtils.checkPwd(pwdReq.getPassword());
        accountService.updatePwdByAdmin(pwdReq);
        return ResponseResultFactory.ucc("修改密码成功！");
    }

    @ApiOperation("更改状态")
    @PostMapping("/update-state")
    public ResponseResult<Object> updateState(
            @ApiParam(name = "记录ID", value = "传入String类型", required = true)
            @RequestBody CustMainAccountModel model) {
        accountService.updateState(model);
        return ResponseResultFactory.ucc("更改状态成功！");
    }

    @ApiOperation("查询商户主账号详情")
    @PostMapping("/query/{id}")
    public ResponseResult<CustMainAccountModel> queryCustomMainAccountList(
            @ApiParam(name = "id", value = "传入json类型", required = true)
            @PathVariable String id) {
        CustMainAccountModel result = accountService.queryByAccountId(id);
        return ResponseResultFactory.ucc("查询成功！", result);
    }
}
